package edu.dut.yz.webdemo.dao;


import edu.dut.yz.webdemo.bean.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserMapper {

    @Select(value="select u_id,username,password from user where username=#{username}")
    @Results({@Result(column = "username",property = "username"),
            @Result(column="password",property = "password"),
            @Result(column="usertype",property = "usertype")
    })
    User getUserByUsername(@Param("username") String username);


//useGeneratedKeys = true（表示自动生成key值）
//keyProperty = "id"（是传给insert语句的属性名，缺省为id）
//keyColumn = "u_id"（数据库中的字段名）

    @Insert(value = "insert into user value(#{id},#{username},#{password},#{usertype})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "u_id")
    void regist(User user);





}
